<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Home\Widget;
use Think\Controller;
class DataWidget extends Controller {

	function rtypename($tid){
		$arr = explode(',', C('RESOURCE_TYPE'));
		foreach ($arr as $k=>$value){
			if($k+1 == $tid){
				echo $value;
			}
		}

	}
	/*
	 * 根据不同视频地址显示视频
	 */
	function getvideo($str){
		$result = null;
		$array_str = explode('##', $str);
		if(is_array($array_str)){
			foreach($array_str as $vi){
				if(!empty($vi)){
					$result .= $this->dispose_video($vi).'<div style="margin-bottom:12px;"></div>';
				}
			}
		}
		echo $result;
	}

	function dispose_video($str){
		if(!empty($str)){
			if(get_domain($str)=="letv.com"){
				echo "<script id=\"autoJsbac53d2d55\" type=\"text/javascript\">var pNode=document.getElementById(\"autoJsbac53d2d55\").parentNode,pt,pb,dWidth = pNode.clientWidth,pHeight = pNode.clientHeight,dHeight = ReCallHeight(pHeight, dWidth,pNode);function ReCallHeight(h, w,a) {try{pt = window.getComputedStyle(a,null).paddingTop;pb = window.getComputedStyle(a,null).paddingBottom;}catch(e){pt = a.currentStyle.paddingTop;pb = a.currentStyle.paddingBottom;}h = h- parseInt(pt)- parseInt(pb);if(h && (typeof h == \"number\") && h==h && h>0){return h;}else{var ua = navigator.userAgent.toLowerCase();var ipad = ua.match(/(iPad).*OS\\s([\\d_]+)/),isIphone = !ipad && ua.match(/(iPhone\\sOS)\\s([\\d_]+)/),isAndroid = ua.match(/(Android)\\s+([\\d.]+)/),isMobile = isIphone || isAndroid;if(isMobile){return w*9/16;}else{return (w*9/16)+36;}}} var letvcloud_player_conf =  {\"uu\":\"".getLetvArray($str,'uu')."\",\"vu\":\"".getLetvArray($str,'vu')."\",\"auto_play\":1,\"gpcflag\":1,\"width\": dWidth,\"height\": dHeight};</script><script type=\"text/javascript\" src=\"http://yuntv.letv.com/bcloud.js\"></script>\n";
			}else if(strstr($str,"youku.com")){
				$str = str_replace('498','200',$str);
				$str = str_replace('510','100%',$str);
				return $str;
			}else if(strstr($str,"qq.com")){
				$str = str_replace('498','200',$str);
				$str = str_replace('640','100%',$str);
				return $str;
			}else if(strstr($str,"cnlive.com")) {
				$str = str_replace('800px', '100%', $str);
				if(ismobile()){
					$str = str_replace('450', 200, $str);
				}else{
					$str = str_replace('450', 400, $str);
				}
				echo $str;
			}else if(strstr($str,"iqiyi.com")){
				$str = str_replace("height=\"100%\"","height=\"200px\"",$str);
				$str = str_replace("height=100%","height=200px",$str);
				return $str;
			}else if(strstr($str,"vf.hrtv.cn")){
				$videoname = str_replace('" width','',getLetvArray($str,'putfile'));
				$videoname = urldecode($videoname);
				$videoname = mb_convert_encoding($videoname, "UTF-8", "gbk");
				$str = "http://vf.hrtv.cn/video/".$videoname.".mp4";
				//echo "<video style=\"background-color:#000;\" src=\"".$str."\" height=\"200\" width=\"100%\" autoplay controls poster webkit-playsinline></video>";
				return "<video style=\"background-color:#000;\" src=\"".$str."\" height=\"200\" width=\"100%\" controls=\"controls\" poster=\"\" webkit-playsinline=\"\"></video>";
			}else{
				return $str;
			}
		}
	}


	/*
	 * 显示位置
	 */
// 	function position($rootid,$flag=null){
// 		if(!empty($flag)){
// 			$submenu = D(C('TABLE_SUBMENU'));
// 			$result = $submenu->where(array('mtypeid'=>$rootid,'mparent'=>0))->select();
// 			foreach ($result as $v){
// 				$presult = $v['position'];
// 				//echo $this->getPositionId($flag,$presult);
// 				if($this->getPositionId($flag,$presult)){
// 					$rArray[] = $v;
// 				}
// 			}
// 			return $rArray;
// 		}else{
// 			return null;
// 		}
		
// 	}
// 	function getPositionId($s,$strresult){
// 		if(!empty($strresult)){
// 			$strresult = explode(',', $strresult);
// 			foreach ($strresult as $v){
// 				if($v==$s){
// 					return true;
// 				}else{
// 					return false;
// 				}
// 			}
// 		}else{
// 			return false;
// 		}
		
		
// 	}

	//获取音频数组
	public function getaudiodata($audioarr){
		if(!empty($audioarr)){
			$audioarr = explode("\r\n",$audioarr);
			foreach($audioarr as $key=>$v){
				if(!empty(trim($v))){
					echo "<li t_artist=\"Transformers2\" t_name=\"Transformers2\"><a href=\"#\">音频".($key+1)."<div class=\"audio-icon\"><i class=\"rukou audio-icon2 play-icon2\">&#xe600;</i></div></a><audio preload=\"none\"><source src=\"".trim($v)."\" type=\"audio/mp3\"></audio></li>";
				}
			}
		}

	}

}
?>